<template>
	<view class="login-container">
		<!-- 显示的图标 -->
		<uni-icons type="contact-filled" size="100" color="#afafaf"></uni-icons>
		
		<!-- 登录的按钮 -->
		<!-- <button class="btn-login" type="primary" open-type="getUserInfo" @getuserinfo = "getUserInfo">点击登录</button> -->
		<button class="btn-login" type="primary" open-type="getUserProfile" @click="getUserInfo">点击登录</button>
		<!-- 提示信息 -->
		<text class="tip-text">点击登录享受更多权限</text>
	</view>
</template>

<script>
	import { mapMutations, mapState } from 'vuex'
	
	export default {
		name:"my-login",
		computed: {
			...mapState('m_user', ['userinfo'])
		},
		data() {
			return {
				canGetUserProfile: false
			};
		},
		methods: {
			
			...mapMutations('m_user', ['updateUserInfo', 'updateToken']),
			
			getUserInfo(e) {
				// console.log(e, 'ressssss'); 
				if(uni.getUserProfile){  
				  // console.log('userprofile');  
				}  
				uni.getUserProfile({  
				  desc: "用于完善用户信息",  
				  success: (e) => { 

					// console.log(e)
					this.updateToken("this is the value of the token of user")
					this.updateUserInfo(e.userInfo)
					uni.$showMessage("登录成功！")
				  }  
				})  
				
				// // 进行登录
				// this.getToken(this.userinfo)
			},
			
			async getToken(info) {
				// 获取code对应的值
				const [err, res] = await uni.login().catch(err => err)
				if (err || res.errMsg !== "login:ok") uni.$showMessage("登录失败！")
				
				console.log(res.code)
				// console.log(info)
				//准备要调用登录的参数
				const query = {
					code: res.code,
					encryptedData: info.encryptedData,
					iv: info.iv,
					rawData: info.rawData,
					signature: info.signature
				}
				
				//调用对应的请求后端的接口进行用户信息验证
				// const { data: loginResult } = await uni.$http.post("对应的路由地址", query);
				// if (返回的状态码 !== 200) uni.$showMessage("登录失败!")

				//更新 vuex 中的token

			}
		}
	}
</script>

<style lang="scss">
.login-container {
	height: 750rpx;
	background-color: #F8F8F8;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	position: relative;
	overflow: hidden;
	
	  // 绘制登录盒子底部的半椭圆造型
	&::after {
		content: ' ';
		display: block;
		position: absolute;
		width: 100%;
		height: 40px;
		left: 0;
		bottom: 0;
		background-color: white;
		border-radius: 100%;
		transform: translateY(50%);
	}
	.btn-login {
		background-color: #EF4E7E;
		width: 80%;
		margin: 15px 0;
		border-radius: 100px;
		font-size: 15px;
	}
	
	.tip-text {
		font-size: 12px;
		color: gray;
	}
}
</style>
